<?php

namespace admin\controllers;

use admin\components\AdminController;
use app\models\AdminGroup;
use app\models\AdminMenu;
use app\utils\ArrayUtils;
use yii\helpers\ArrayHelper;

class UserGroupController extends AdminController {

    public $name = '管理员组';

    public function actionIndex() {
        $searchModel = !$this->enableSearch ? NULL : new AdminGroup();

        $query = AdminGroup::find();
        $dataProvider = $this->search($query, $searchModel);
        return $this->render(compact('searchModel', 'dataProvider'));
    }


    public function actionSave($id = FALSE) {
        $adminMenu = new AdminMenu();
        $lists = $adminMenu->access();
        $menus = ArrayUtils::arrayTreeIndex($lists);
        //print_r($menus);exit;

        /* @var $model AdminGroup */
        $model = $this->findModel($id, AdminGroup::className());
        $model->privilege_ids = $model->getPrivilegeIds();
        if (!$model->load($this->post())) {
            return $this->render(compact('model', 'menus'));
        }
        return $model->save();
    }

}
